<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="检验单编号" prop="iqcCode">
        <el-input v-model="queryParams.iqcCode" placeholder="请输入送检单号" clearable />
      </el-form-item>
      <!-- <el-form-item label="物料名称" prop="itemName">
        <el-input v-model="queryParams.itemName" placeholder="请输入物料名称" clearable />
      </el-form-item>

      <el-form-item label="检验状态" prop="fqcstatus">
        <el-select v-model="queryParams.fqcstatus" placeholder="请选择">
          <el-option label="未检验" :value="0"></el-option>
          <el-option label="已检验" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="检验日期" prop="inspectDate">
        <el-date-picker
          clearable
          v-model="queryParams.inspectDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择检验日期"
        ></el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="iqcList">
      <el-table-column label="序号" align="center" width="50px" prop="issueCode">
        <template slot-scope="scope">
          <span>{{scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="检验单编号" width="140px" align="center" prop="iqcCode" >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">{{ scope.row.iqcCode }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="单据编号" align="center" prop="fbillno" />
      <el-table-column label="供应商" align="center" prop="vendorName" />
      <el-table-column label="收料日期" align="center" prop="putDate" />
      <el-table-column label="质检状态" width="120px" align="center" prop="qualityStatus">
        <template
          slot-scope="scope"
        >{{ scope.row.qualityStatus =='0' ? "未质检 " :scope.row.qualityStatus =='1'?"质检中":scope.row.qualityStatus =='2'?"已质检" : "--" }}</template>
      </el-table-column>
      <!-- <el-table-column label="审核员" width="120px" align="center" prop="auditor"/> -->
      <!-- <el-table-column label="审核时间" width="120px" align="center" prop="auditDate"/> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <iqcIndex ref="details" ></iqcIndex>
    <!-- iqcIndex -->
  </div>
</template>

<script>
import iqcIndex from "./indexIqc.vue";
import {
  listIqcHead,
  getIqc,
  delIqc,
  addIqc,
  updateIqc,
  getinspectData,
  submitQcIqc
} from "@/api/mes/qc/iqc";
import ItemSelect from "@/components/itemSelect/single.vue";
import VendorSelect from "@/components/vendorSelect/single.vue";
import IqcLine from "./iqcline.vue";
import { genCode } from "@/api/mes/md/rule";
import { getReport, getReport2 } from "@/api/mes/report/report";
import { addItemrecpt, addItemrecptData } from "@/api/mes/wm/itemrecpt";
export default {
  name: "Iqc",
  dicts: ["mes_qc_result", "mes_order_status"],
  components: { ItemSelect, VendorSelect, IqcLine, iqcIndex },
  data() {
    return {
      //自动生成编码
      autoGenFlag: false,
      optType: undefined,
      acceptImg: require("@/assets/images/accept.png"),
      rejectImg: require("@/assets/images/reject.png"),
      prepareImg: require("@/assets/images/prepare.png"),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 来料检验单表格数据
      iqcList: [
        {
          inspectionNo: "1145522"
        }
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        iqcCode: null,
        iqcName: null
      },
      // 表单参数
      form: {},
      // 模板列表
      templateList: [],
      loading1: false,
      // 不合格数
      failedSncode: [],
      // 序列码集合
      snObj: {},
      //异常列表
      abnormalList: [],
      // 表单校验
      rules: {
        iqcCode: [
          { required: true, message: "来料检验单编号不能为空", trigger: "blur" }
        ],
        iqcName: [
          { required: true, message: "来料检验单名称不能为空", trigger: "blur" }
        ],

        vendorCode: [
          { required: true, message: "供应商不能为空", trigger: "blur" }
        ],
        itemCode: [
          { required: true, message: "物料不能为空", trigger: "blur" }
        ],
        quantityRecived: [
          { required: true, message: "本次接收数量不能为空", trigger: "blur" }
        ],
        quantityCheck: [
          { required: true, message: "本次检测数量不能为空", trigger: "blur" }
        ],
        reciveDate: [
          { required: true, message: "清选择来料日期", trigger: "blur" }
        ],
        inspectDate: [
          { required: true, message: "清选择检验日期", trigger: "change" }
        ]
      },
      //详情页面
      detailVisible: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询来料检验单列表 */
    getList() {
      this.loading = true;
      listIqcHead(this.queryParams).then(response => {
        this.iqcList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleView(row){
      this.$nextTick(() => {
        this.$refs.details.init(row);
      });
    }
  }
};
</script>
